var app = getApp();
var url = app.globalData.url;
Page({
  data: {
    src: '/images/touxiang.jpg',
    order:{},
    totalCount: 0,
  },
  onLoad:function(data){
    var that = this;
    console.log(data.orderNo);
    wx.request({
      url: url+'queryOrderNo.action',
      data: {
        orderNo: data.orderNo
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      method: 'post',
      success: function (res) {
        console.log(res);
        var order = res.data.data;
        var orders = new Object();
        orders.orderId = order[0][0].orderId;
        orders.orderNo = order[0][0].orderNo;
        orders.uId = order[0][0].uId;
        orders.tableNo = order[0][0].tableNo;
        orders.pNum = order[0][0].pNum;
        orders.remark = order[0][0].remark;
        orders.createTime = order[0][0].createTime;
        orders.totalMoney = order[0][0].totalMoney;
        orders.payType = order[0][0].payType;
        orders.struts = order[0][0].struts;
        var orderDetail =[];
        for (var i = 0; i < order.length;i++){
          var details = new Object();
          details.oDId = order[i][1].oDId;
          details.orderId = order[i][1].orderId;
          var T_dishe =order[i][2];
          details.T_dishes = T_dishe;
          details.fCount = order[i][1].count;
          details.cooked = order[i][1].cooked;
          orderDetail.push(details);
        }
        orders.orderDetail = orderDetail;
        that.setData({
          order: orders
        });
        var Count = that.data.order.orderDetail;
        var sumCount = 0;
        for (var i = 0; i < Count.length; i++) {
          sumCount += Count[i].fCount;
        }
        that.setData({
          totalCount: sumCount
        });
        console.log(that.data.order);
        console.log(that.data.totalCount);
      }
    })
    this.hh();
  },
  /**
   * 点击买单
   */
  pay_ok:function(e){
    var orderId = this.data.order.orderId;
    var orderNo = this.data.order.orderNo;
    var Money = this.data.order.totalMoney;
    var createTime = this.data.order.createTime;
    wx.navigateTo({
      url: '/pages/pay/pay?orderId=' + orderId + '&orderNo=' + orderNo + '&totalMoney=' + Money + '&createTime=' + createTime,
    })
  },
  /**
   * 画虚线
   */
  hh: function () {
    var context = wx.createContext()//创建并返回绘图上下文context对象
    context.setStrokeStyle("#1C1C1C")//设置线条的颜色
    context.setLineWidth(1)//设置线条宽度
    function drawDashLine(ctx, x1, y1, x2, y2, dashLength) {  //传context对象，始点x和y坐标，终点x和y坐标，虚线长度
      var dashLen = dashLength === undefined ? 3 : dashLength,
        xpos = x2 - x1, //得到横向的宽度;
        ypos = y2 - y1, //得到纵向的高度;
        numDashes = Math.floor(Math.sqrt(xpos * xpos + ypos * ypos) / dashLen);
      //利用正切获取斜边的长度除以虚线长度，得到要分为多少段;
      for (var i = 0; i < numDashes; i++) {
        if (i % 2 === 0) {
          ctx.moveTo(x1 + (xpos / numDashes) * i, y1 + (ypos / numDashes) * i);
          //有了横向宽度和多少段，得出每一段是多长，起点 + 每段长度 * i = 要绘制的起点；
        } else {
          ctx.lineTo(x1 + (xpos / numDashes) * i, y1 + (ypos / numDashes) * i);
        }
      }
      ctx.stroke();
    }
    drawDashLine(context, 0, 0, 400, 0, 3);//横向虚线
    //微信小程序画图
    wx.drawCanvas({
      canvasId: 'canvas',
      actions: context.getActions()
    });
  }
})